﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Lin.EFData;
using Lin.EFData.Table;
using Lin.Library.Extensions;

namespace Lin.Website.Api
{
    public class AdminController : ApiController
    {
        /// <summary>
        /// 根据用户名密码验证用户是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        [HttpPost]
        public LinUser LoginAuth(Dictionary<string,string> user)
        {
          
            using (var context = new SysContext())
            {
                var name = user["name"];
                var pass = user["pass"];

                pass = (name + pass).ToHash();

                return context.LinUser.FirstOrDefault(u => u.uName == name && u.uPass == pass && u.uStop == false);

            }
        }

        // GET api/<controller>
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/<controller>/5
        public string Get(int id)
        {
            return "value";
        }

        public IList<string> Test() {
            var list = new List<string>();
            list.Add("aa");
            list.Add("bb");
            return list;
        }

        // POST api/<controller>
        public void Post([FromBody]string value)
        {

        }

        // PUT api/<controller>/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/<controller>/5
        public void Delete(int id)
        {
        }
    }
}